<?php
namespace Home\Model;

use Think\Model;

class AddressModel extends Model
{
	protected $_validate = array(
		array('shname','chk_require','收件人姓名必须',1,'callback',3),

		
	    //手机号验证
	    array('phone','chk_require','手机号必须',1,'callback',3),
	    array('phone','chk_phone','手机格式错误!',1,'callback'), 

	    array('province','chk_province','请选择省份信息',1,'callback',3),
	   
	    array('city','chk_city','请选择市级信息',1,'callback',3),

	    array('county','chk_county','请选择县级信息',1,'callback',3),

	    array('village','chk_require','请填写街道信息',1,'callback',3),

	    array('detail_site','chk_require','请填写详细地址',1,'callback',3),
	);



	protected $_auto = array(
		
		array('addtime','time',1,'function'),//创建时间
		array('user_id',"user_id",1,'callback'),
	);


	function user_id(){
		return session('user_id');
	}
    //不为空
	function chk_require($val){

		$rule = '/\S+/';
		if(!preg_match($rule,$val)){
            return false;
        }
	}

	function chk_province($val){

		if($val == '省份'){
            return false;
        }
	}
	function chk_city($val){

		if($val == '地级市' ){
            return false;
        }
	}
	function chk_county($val){

		if($val == '市、县级市'){
            return false;
        }
	}

	//手机格式验证
	function chk_phone($phone){

		$rule = '/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/';
		if(!preg_match($rule,$phone)){
            return false;
        }
	}


	

}
?>